<%--
  Created by IntelliJ IDEA.
  User: 00
  Date: 2018/2/26
  Time: 1:32
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="/WEB-INF/jsp/comm/head.jsp"%>
    <title>Title</title>
</head>
<body>
<div class="container">
    <div class="panel panel-default">
        <div class="panel-heading">
            条件查询
        </div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="form-group">
                    <%--@declare id=""--%><label for="" class="control-label">任务编号：</label>
                    <input type="text" name="inspectionTaskCode" class="form-control"/>
                </div>
                <div class="form-group">
                    <label for="" class="control-label">线路管理：</label>
                    <input type="text" name="lineName"  class="form-control"/>
                </div>
                <div class="form-group">
                    <label for="" class="control-label">任务状态：</label>
                    <select name="configValueId" class="form-control">
                        <option value="-1">--请选择--</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="" class="control-label">下发人：</label>
                    <input type="text" name="issuedByName" class="form-control"/>
                </div>

                <div class="form-group">
                    <button type="button" class="btn btn-danger" onclick="xjcx()"><i class="glyphicon glyphicon-search"></i> 查询</button>
                </div>
            </form>
        </div>
    </div>

    <c:if test="${loginUser.roleId!=3}">
        <button class="btn btn-danger" onclick="xjadd()" type="button"><i class="glyphicon glyphicon-plus-sign"></i> 制定巡检任务</button>
    </c:if>

    <table id="table"
           data-toggle="table"
           data-url="${ctx}/zdfp/rwzdfp"
           data-striped="true"
           data-pagination="true"
           data-side-pagination="server"
           data-page-size="4"
           data-page-list="[4,8,12,16,20]"
           data-query-params="queryParams"
           data-toolbar="toolbar">
        <thead>



        <tr>
            <th data-field="inspectionTaskCode">任务编号</th>
            <th data-field="inspectionTaskName">任务名称</th>
            <th data-field="lineName">巡查路线</th>
            <th data-field="startPolecode">起始编号</th>
            <th data-field="endPolecode">终止编号</th>
            <th data-field="issuedByName">下发人</th>
            <th data-field="issuedTime">下发时间</th>
            <th data-field="taskStatusName" data-formatter="taskFor">任务状态</th>
            <th data-field="finishTime">完成任务时间</th>
            <th data-field="isCancel" data-formatter="yesno">任务是否取消</th>
            <th id="xunjian" data-events="events" data-formatter="formOpt">操作</th>
        </tr>
        </thead>
    </table>

    <div id="xjshow">
        <form action="" class="form-horizontal">
            <div class="form-group">
                <div class="col-md-6">
                    <input type="hidden" name="id" class="form-control">

            <div class="form-group">
                <label for="" class="col-md-4 control-label">任务编号:</label>
                <div class="col-md-8">
                    <input type="text" name="inspectionTaskCode" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">任务名称:</label>
                <div class="col-md-8">
                    <input type="text" name="inspectionTaskName" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">巡检路线:</label>
                <div class="col-md-8">
                    <input type="text" name="lineName" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">起始编号:</label>
                <div class="col-md-8">
                    <input type="text" name="startPolecode" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">终止编号:</label>
                <div class="col-md-8">
                    <input type="text" name="endPolecode" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">下发人:</label>
                <div class="col-md-8">
                    <input type="text" name="issuedByName" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">下发时间:</label>
                <div class="col-md-8">
                    <input type="text" name="issuedTime" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">任务状态:</label>
                <div class="col-md-8">
                    <input type="text" name="taskStatusName" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">完成时间:</label>
                <div class="col-md-8">
                    <input type="text" name="finishTime" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">备注信息:</label>
                <div class="col-md-8">
                    <textarea name="common" style="width:350px;height:80px;" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-4 control-label">巡检员:</label>
                <div class="col-md-8">
                    <input type="text" name="inspectorName" class="form-control">
                </div>
            </div>
                </div>
            </div>
        </form>
    </div>
    <div id="add">
        <form action="" class="form-horizontal" method="post">
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">任务编号：</label>
                        <div class="col-md-9">
                            <input type="text" name="inspectionTaskCode" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">任务名称：</label>
                        <div class="col-md-9">
                            <input type="text" name="inspectionTaskName" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="hidden" name="lineId" class="form-control">
                    </div>
                    <div class="form-group">
                        <input type="hidden" name="lineCode" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">巡检线路：</label>
                        <div class="col-md-9">
                            <select name="lineName" id="lineName" class="form-control" onclick="userzt()">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">巡检员：</label>
                        <div class="col-md-9">
                            <input type="hidden" id="userId" class="form-control">
                            <select name="userId" class="form-control">
                                <%--<option value="">--请选择--</option>--%>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                            <input type="hidden" name="startPole" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">起始杆号：</label>
                        <div class="col-md-9">
                            <input type="text" name="startPolecode" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="hidden" name="endPole" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">终止杆号：</label>
                        <div class="col-md-9">
                            <input type="text" name="endPolecode" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="hidden" name="issuedByCode" value="${loginUser.userCode}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">下发人：</label>
                        <div class="col-md-9">
                            <input type="text" value="${loginUser.userName}" name="issuedByName" class="form-control" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">下发日期：</label>
                        <div class="col-md-9">
                            <p data-formatter=="showTime()"></p>
                            <div id="da">
                                <div id="time"></div>
                                <div id="shijian"></div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-md-3 control-label">备注：</label>
                        <div class="col-md-9">
                            <textarea name="common" style="width:350px;height:80px;" class="form-control"></textarea>
                        </div>
                    </div>
        </form>
    </div>



    <div id="update">
        <form action="" class="form-horizontal" method="post">
            <div class="form-group">
                <div class="col-md-9">
                    <input type="hidden" name="id" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">任务编号：</label>
                <div class="col-md-9">
                    <input type="text" name="inspectionTaskCode" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">任务名称：</label>
                <div class="col-md-9">
                    <input type="text" name="inspectionTaskName" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" name="lineId" class="form-control">
            </div>
            <div class="form-group">
                <input type="hidden" name="lineCode" class="form-control">
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">巡检线路：</label>
                <div class="col-md-9">
                    <select name="lineName" class="form-control">
                        <option value="-1">--请选择--</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">巡检员：</label>
                <div class="col-md-9">
                    <select name="userName" class="form-control">
                        <option value="">--请选择--</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" name="startPole" class="form-control">
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">起始杆号：</label>
                <div class="col-md-9">
                    <input type="text" name="startPolecode" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" name="endPole" class="form-control">
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">终止杆号：</label>
                <div class="col-md-9">
                    <input type="text" name="endPolecode" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" name="issuedByCode" class="form-control">
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">下发人：</label>
                <div class="col-md-9">
                    <input type="text" name="issuedByName" class="form-control" readonly>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">下发日期：</label>
                <div class="col-md-9">
                    <input type="text" name="issuedTime" class="form-control" readonly="readonly">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">备注：</label>
                <div class="col-md-9">
                    <textarea name="common" style="width:350px;height:80px;" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>



    <div id="fpupdate">
        <form action="" class="form-horizontal" method="post">
            <div class="form-group">
                <input type="hidden" id="id" name="id" class="form-control">
                <label for="" class="col-md-3 control-label">巡检员：</label>
                <div class="col-md-9">
                    <select name="userId" class="form-control">
                        <%--<option value="">--请选择--</option>--%>
                    </select>
                </div>
            </div>
        </form>
    </div>




<%@include file="/WEB-INF/jsp/comm/foot.jsp"%>
    <script src="${ctx}/static/myjs/xjrwzdfp.js"></script>
    <script>



        function yesno(value,row){
            return value==0?"否":"是";
        }

        function taskFor(value,row){
            if(row["taskStatusName"]=="待分配"){
                return "<span style='color: orange'>待分配</span>"
            }
            else if(row["taskStatusName"]=="已分配"){
                return "<span style='color: blue'>已分配</span>"
            }
            else if(row["taskStatusName"]=="执行中"){
                return "<span style='color: purple'>执行中</span>"
            }else{
                return "<span style='color: green'>已完成</span>"
            }
        }



        $(function(){
            $.getJSON(ctx+"zdfp/search1",function(arr){
                $(arr).each(function(){
                    var $opt=$("<option/>");
                    $opt.html(this.configValueName);
                    $opt.val(this.configValueId);
                    $opt.appendTo("[name=configValueId]");
                });
            });
        });





        function formOpt(value,rwo){

            var getshow = `<button class="btn btn-info edit getshow" ><i class="glyphicon"></i> 查看</button> `;
            var fpupdate=`<button class="btn btn-info fpupdate" ><i class="glyphicon"></i> 分配任务</button> `;
            var update=`<button class="btn btn-info update" ><i class="glyphicon"></i> 修改</button> `;
            var edit4=`<button class="btn btn-info edit4" ><i class="glyphicon"></i> 取消</button> `;
            return getshow+fpupdate+update+edit4;
        }

        var events={
            "click .getshow":function(e,value,row){
                getshow(row);
            },
            "click .fpupdate":function(e,value,row){
                fpupdate(row);
            },
            "click .update":function(e,value,row){
                update(row);
            },
            "click .edit4":function(e,valuew,row){
                shanchu(row);
            }
        }

        /**
         * 详细查看
         * @param row
         */
        $(function () {
            $("#xjshow").dialog({
                title:"详细查看",

                btnBind:function () {

                }
            });
        });




           function getshow(row){
            for (var prop in row) {
                if (prop == 'isCancel') {
                    var a = row[prop] == 0 ? "否" : "是";
                    $("#xjshow").find("[name=" + prop + "]").val(a);
                    continue;
                }
                $("#xjshow").find("[name=" + prop + "]").val(row[prop]);
            }
            $("#xjshow").dialog("open");
           }

        $(function(){
            $.getJSON(ctx+"zdfp/search2",function(arr){
                $(arr).each(function(){
                    var $opt=$("<option/>");
                    $opt.html(this.lineName);
                    $opt.val(this.lineName);
                    $opt.attr("data-line",JSON.stringify(this));
                    $opt.appendTo("[name=lineName]");
                });
            });
            $("#lineName").change(function(){
                var data = JSON.parse($(this).find("option:selected").attr("data-line"));
                $("#add [name=startPolecode]").val(data.startPolecode);
                $("#add [name=endPolecode]").val(data.endPolecode);
                $("#add [name=startPole]").val(data.startPole);
                $("#add [name=endPole]").val(data.endPole);
                $("#add [name=lineCode]").val(data.lineCode);
                $("#add [name=lineId]").val(data.id);
            });
        });

        $(function(){
            loadXJY();
            $("[name=userName]").change(function(){
                if($("[name=userName]").val()!=-1){
                    $("[name=id]").val(id);
                }else if($("[name=userName]").val()==-1){
                    $("[name=id]").val(null);
                }
            })
        });



        $(function(){
            $("#add").dialog({
                title:"添加缺陷类型",
                btnName:"确定",
                btnBind:function(){

                    var userId = $('[name=userId]').val();
                    var userName = $('[name=userId] option[value='+userId+']').html();

                    console.log('userId='+userId);
                    var param=$("#add form").serialize();
                    console.log(param);
                    var taskStatus;
                    var taskStatusName;
                    if(userId!=-1){
                        taskStatus=2;
                        taskStatusName="已分配";
                        userName=userName;
                    }else{
                        taskStatus=1;
                        taskStatusName="待分配";
                        userName=null;
                    }
                    param+="&id="+userId;
                    param+="&userName="+userName;
                    param+="&taskStatus="+taskStatus;
                    param+="&taskStatusName="+taskStatusName;
                    $.post(ctx+"zdfp/add",param,function (isOk){
                        toastr.warning("信息提示",isOk);
                        $("#add").dialog("close");
                        $("#table").bootstrapTable("refresh");
                    },'text')
                }
            });
        });
        function xjadd(){
            $("#add form")[0].reset();
            $("#add").dialog("open");
            loadXJY();
        }

        /**
         * 修改
         */

        $(function(){
            $("#update").dialog({
                title:"修改",
                btnName:"确定",
                size:'modal-lg',
                btnBind:function(){
                    var param=$("#update form").serialize();
                    $.post(ctx+"zdfp/update",param,function(msg){
                        toastr.warning("信息提示",msg);
                        $("#update").dialog("close");
                        $("#table").bootstrapTable("refresh");
                    },'text')
                }
            });
        });
        function update(row) {
            for(var prop in row){
                $("#update").find("[name="+prop+"]").val(row[prop]);
            }
            $("#update").dialog("open");
        };

        /**
         * 分配任务
         */
         $(function(){
             $("#fpupdate").dialog({
                 title:"分配任务",
                 btnName:"确认",
                 btnBind:function(){
                     var id =$("#fpupdate [name=id]").val();
                     var userId = $('[name=userId]').val();
                     var param=$("#fpupdate form").serialize();
                     var userName=$('[name=userId] option[value='+userId+']').html()
                     var taskStatus;
                     var taskStatusName;
                     if(userId!=-1){
                         taskStatus=2;
                         taskStatusName="已分配";
                         userName="2";
                     }else{
                         taskStatus=1;
                         taskStatusName="待分配";
                         userName="1";
                     }param+="&id="+id;
                     param+="&userId="+userId;
                     param+="&userName="+userName;
                     param+="&taskStatus="+taskStatus;
                     param+="&taskStatusName="+taskStatusName;

                     $.post(ctx+"zdfp/fpUpdate",param,function (msg) {
                         toastr.warning("信息提示",msg);
                         $("#fpupdate").dialog("close");
                         $("#table").bootstrapTable("refresh");
                     },'text')
                 }
             });
         });
        function fpupdate(row) {
            var taskStatus=row["taskStatus"];
            if(taskStatus==1){
                for(var prop in row){
                    $("#fpupdate").find("[name="+prop+"]").val(row[prop]);
                }
                $("#fpupdate").dialog("open");
                loadXJY();
            }else{
                return;
            }
        };


        /**
         * 取消任务
         */

        function shanchu(row){
            var isCancel;
                if(row["isCancel"]==0){
                    isCancel=1;
                }else{
                    isCancel=0;
                }
                $.post(ctx+"zdfp/delete",{id:row["id"],isCancel:isCancel},function(isOk){
                    toastr.warning("信息提示",isOk);
                    $("#table").bootstrapTable("refresh");
            })
        }

//        function userzt(row){
//            var xjzt;
//            if(row["xjzt"]==0){
//                xjzt=1;
//            }
//            $.post(ctx+"zdfp/add",{id:row["id"],id:xjzt},function (isOk) {
//            })
//        }






//        <select name="userName" class="form-control"> <option value="-1">--请选择--</option></select>
        function loadXJY(){
            $("[name=userId]").html($('<option value="-1">--请选择--</option>'))
            $.getJSON(ctx+"zdfp/search3",function(arr){
                $(arr).each(function(){
//                    alert(this.userName)
                    var $opt=$("<option value="+this.id+">"+this.userName+"</option>");
                    $("[name=userName]").html()
                    $("[name=userName]").val()
                    $opt.html(this.userName);
                    $opt.val(this.id);
                    $opt.appendTo("[name=userId]");
                });
            });
        }






        function showTime(){
            var today = new Date();

            var year = today.getFullYear();
            var month = today.getMonth()+1;
            var day = today.getDate();
            //var hour = today.getHours();
            var hour = ("0" + (today.getHours())).slice(-2);
            var minute = ("0" + (today.getMinutes())).slice(-2);
//            var seconds =("0" + (today.getSeconds())).slice(-2);
//            var haom=("0" + (today.getMilliseconds())).slice(-2);
            //var times = today.getTime();
            //var mytime=today.toLocaleTimeString();
            /*if(hour<11){
             0+hour;
             }else{
             hour;
             }*/

            var time =year+" - "+month+" - "+day;

            document.getElementById("time").innerHTML = time;
        }


        var t = setInterval("showTime()");

        function stopTime(){
            clearInterval(t);
        }
        function startTime(){
            t = setInterval("showTime()");
        }



    </script>
</body>
</html>
